import ace from "ace-builds";
/* 启用此行后webpack打包回生成很多动态加载的js文件，不便于部署，故禁用！！
     特别提示：禁用此行后，需要调用ace.config.set('basePath', 'path...')指定动态js加载URL！！
   */
//import 'ace-builds/webpack-resolver'

import "ace-builds/src-min-noconflict/theme-monokai"; // 默认设置的主题
// import "ace-builds/src-min-noconflict/theme-sqlserver"; // 新设主题
import "ace-builds/src-min-noconflict/mode-javascript"; // 默认设置的语言模式
import "ace-builds/src-min-noconflict/mode-json"; //
import "ace-builds/src-min-noconflict/mode-css"; //
import "ace-builds/src-min-noconflict/ext-language_tools";
// import {ACE_BASE_PATH} from "@/utils/config";

//代码片段加载
import fragment from "./fragment/index"

ace.config.set(
    "basePath",
    "https://ks3-cn-beijing.ksyun.com/vform2021/ace"
);

const addAutoCompletion = (ace: { require: (arg0: string) => any; }) => {
    let acData = [...fragment];
    let langTools = ace.require("ace/ext/language_tools");
    langTools.addCompleter({
        getCompletions: function (editor: any, session: any, pos: any, prefix: string | any[], callback: (arg0: null, arg1: { meta: string; caption: string; type: string; snippet: string; score: number; }[]) => any) {
            if (prefix.length === 0) {
                return callback(null, []);
            } else {
                return callback(null, acData);
            }
        },
    });
}

addAutoCompletion(ace); //添加自定义代码提示！！
window.ace=ace